<?php

namespace App\Http\Controllers;

use App\Http\Resources\GoodsModelResource;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    // CMS图片服务器地址
    const STORAGE_HOST = 'https://erp.toysmodel.cn:11443';
    // 上图图片服务器地址
    const DISK_HOST = 'https://picture.toysmodel.cn:11443/Inf';
    // 缩略图路径
    const THUMBNAIL_PATH = '/UpLoad/';
    // 原图路径
    const ORIGINAL_PATH = '/EnPic/';

    /**
     * 获取图片全路径
     * @param $image
     * @param bool $thumbnail
     * @return string
     */
    public static function getImageFullUrl($image, bool $thumbnail = false): string
    {
        if ($thumbnail)
            return GoodsModelResource::THUMBNAIL_PREFIX . $image->Path . DIRECTORY_SEPARATOR . $image->FName;
        else {
            list($name, $ext) = explode('.', $image->FName);
            return GoodsModelResource::IMAGE_PREFIX . $image->Path . DIRECTORY_SEPARATOR . $name . '.dat';
        }
    }
}
